package com.shengzai.mapreduce.wordcount;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

import java.io.IOException;

public class DriverWorldCount {
    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException {
        //  ① 创建一个Job实例对象，并且设置其名称和当前的入口类
        //	② 设置MapReduce中自定义的mapper和Reducer的类名称
        //	③ 设置Map端输出的Key及Value类
        //	④ 设置最终输出的Key和Value类
        //	⑤ 设置输入输出的数据路径
        //	⑥ 执行
        Configuration entries = new Configuration();
        Job job = new Job(entries);
        job.setJobName("WorldCount");
        job.setJarByClass(DriverWorldCount.class);

        job.setMapperClass(MapWorldCount.class);
        job.setReducerClass(ReduceWorldCount.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);

        TextInputFormat.addInputPath(job,new Path("/input/worlds.txt"));
        TextOutputFormat.setOutputPath(job,new Path("/output/world_count"));

        job.waitForCompletion(true);
    }
}
